package mo.tags.stack;

import mo.common.TreeNode;

public class L114 {

    public void flatten(TreeNode root) {
        traverse(root);
    }

    private void traverse(TreeNode root) {
        if (root == null) {
            return;
        }
        TreeNode left = root.left;
        TreeNode right = root.right;
        root.right = left;
        root.left = null;
        TreeNode t = root;
        while (t.right != null) {
            t = t.right;
        }
        t.right = right;
        traverse(root.right);
    }

}
